package day_2022_4_to_7.day48;

/**
 * 手套
 * @author haomin
 * @date 2022/05/10 21:00
 **/
public class Day15_2_findMinimum {
    public int findMinimum(int n, int[] left, int[] right) {
        int sum = 0;
        int leftSum = 0,rightSum = 0;
        int leftMin = 30,rightMin = 30;

        for (int i = 0; i < n; i++) {
            if(left[i] * right[i] == 0){
                sum = sum + left[i] + right[i];
            }else {
                leftSum += left[i];
                rightSum += right[i];
                leftMin = Math.min(leftMin,leftSum);
                rightMin = Math.min(rightMin,right[i]);
            }
        }
        return sum + Math.min(leftSum-leftMin+1,rightSum-rightMin+1) + 1;
    }
}